const url = "https://www.jxselab.com:8000/"
const url1 = "http://localhost:8000/"
async function uploadFile(file) {
  if (!file) {
    console.error('No file provided for upload.');
    return;
  }

  const formData = new FormData();
  formData.append('file', file);

  try {
    const response = await fetch(`${url}sapperchain/uploadfile`, {
      method: 'POST',
      body: formData,
    });

    if (response.ok) {
      const data = await response.json();
      console.log(`File uploaded successfully! URL: ${data.url}`);
      return data.url; // 返回文件的 URL
    } else {
      const errorText = await response.text();
      console.error(`Failed to upload file. Status: ${response.status}, Message: ${errorText}`);
    }
  } catch (error) {
    console.error('Upload error:', error);
  }
}

export default uploadFile;
